package com.hzlj.position.locate.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fz.common.base.converter.QueryWrapperConverterPlus;
import com.fz.common.base.dto.PageParamDTO;
import com.fz.common.base.dto.QueryPageResultDTO;
import com.hzlj.position.locate.common.dto.reportVideo.ReportVideoQueryParamDTO;
import com.hzlj.position.locate.common.dto.reportVideo.ReportVideoWithJzJbxxDTO;
import com.hzlj.position.locate.common.model.ReportVideo;
import com.hzlj.position.locate.common.model.ReportVideoJzry;
import com.hzlj.position.locate.mapper.ReportVideoMapper;
import com.hzlj.sqjz.jz.common.constant.JzJoin;
import com.hzlj.sqjz.jz.common.model.JzJbxx;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 通信联络核查-视频核验(ReportVideo)表操作类
 *
 * @author lifh
 * @date 2023-03-13 19:10:17
 */
@Repository
public class ReportVideoDao extends ServiceImpl<ReportVideoMapper, ReportVideo> {
    @Resource
    private ReportVideoMapper reportVideoMapper;

    /**
     * 删除数据
     */
    public void delete(String jzId, Date now) {
        LambdaUpdateWrapper<ReportVideo> deleteWrapper = new UpdateWrapper<ReportVideo>().lambda()
                .eq(ReportVideo::getJzId, jzId)
                .eq(ReportVideo::getBelongDay, now);
        this.remove(deleteWrapper);
    }

    /**
     * 修改数据
     */
    public boolean updateReportVideo(ReportVideo dto) {
        LambdaQueryWrapper<ReportVideo> queryWrapper = new QueryWrapper<ReportVideo>().lambda()
                .eq(ReportVideo::getId, dto.getId());
        return this.update(dto, queryWrapper);
    }


    public ReportVideo getReportVideoByBussId(String bussId, String jzId) {
        LambdaQueryWrapper<ReportVideo> queryWrapper = new QueryWrapper<ReportVideo>().lambda()
                .eq(ReportVideo::getBussId, bussId)
                .eq(ReportVideo::getJzId, jzId);
        return this.getOne(queryWrapper);
    }


    /**
     * 查询列表：列表
     */
    public List<ReportVideoWithJzJbxxDTO> listReportVideo(ReportVideoQueryParamDTO dto) {
        return QueryWrapperConverterPlus.of(reportVideoMapper)
                .innerJoin(JzJbxx.class, JzJoin.zj(ReportVideo::getJzId))
                .leftJoin(ReportVideoJzry.class, on -> on.eq(ReportVideoJzry::getId, ReportVideo::getJzId))
                .list(ReportVideoWithJzJbxxDTO.class, dto);
    }

    /**
     * 查询列表：分页
     */
    public QueryPageResultDTO<ReportVideoWithJzJbxxDTO> pageReportVideo(ReportVideoQueryParamDTO dto, PageParamDTO page) {
        return QueryWrapperConverterPlus.of(reportVideoMapper)
                .innerJoin(JzJbxx.class, JzJoin.zj(ReportVideo::getJzId))
                .leftJoin(ReportVideoJzry.class, on -> on.eq(ReportVideoJzry::getId, ReportVideo::getJzId))
                .page(ReportVideoWithJzJbxxDTO.class, dto, page);
    }

}

